<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
          <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="530px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
          <el-form-item label="舷号">
            <el-input v-model="form.shipNo" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="部署系统1型号">
            <el-input v-model="form.systemType1" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="部署系统2型号">
            <el-input v-model="form.systemType2" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="部署系统1版本">
            <el-input v-model="form.systemVersion1" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="部署系统2版本">
            <el-input v-model="form.systemVersion2" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="开始时间">
            <el-date-picker v-model="form.startTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="结束时间">
            <el-date-picker v-model="form.endTime" type="datetime" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('id')" prop="id" label="ID" />
        <el-table-column v-if="columns.visible('shipNo')" prop="shipNo" label="舷号" />
        <el-table-column v-if="columns.visible('systemType1')" prop="systemType1" label="部署系统1型号" />
        <el-table-column v-if="columns.visible('systemType2')" prop="systemType2" label="部署系统2型号" />
        <el-table-column v-if="columns.visible('systemVersion1')" prop="systemVersion1" label="部署系统1版本" />
        <el-table-column v-if="columns.visible('systemVersion2')" prop="systemVersion2" label="部署系统2版本" />
        <el-table-column v-if="columns.visible('startTime')" prop="startTime" label="开始时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.startTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('endTime')" prop="endTime" label="结束时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.endTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-permission="['admin','shipSoftVersion:edit','shipSoftVersion:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudShipSoftVersion from '@/api/shipSoftVersion'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '舰艇软件版本信息', url: 'api/shipSoftVersion', sort: 'id,desc', crudMethod: { ...crudShipSoftVersion }})
const defaultForm = { id: null, shipNo: null, systemType1: null, systemType2: null, systemVersion1: null, systemVersion2: null, startTime: null, endTime: null }
export default {
  name: 'ShipSoftVersion',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
      permission: {
        add: ['admin', 'shipSoftVersion:add'],
        edit: ['admin', 'shipSoftVersion:edit'],
        del: ['admin', 'shipSoftVersion:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'id', display_name: 'ID' },
        { key: 'shipNo', display_name: '舷号' },
        { key: 'systemType1', display_name: '部署系统1型号' },
        { key: 'systemType2', display_name: '部署系统2型号' },
        { key: 'systemVersion1', display_name: '部署系统1版本' },
        { key: 'systemVersion2', display_name: '部署系统2版本' }
      ]
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }
      return true
    }
  }
}
</script>

<style scoped>

</style>
